﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BitBox.Framework.Util;
using BitBox.Framework.KBR.Model;

namespace BitBox.XnaWindowsGame.KBR
{
    public class UserDataProxy
    {
        #region /* Métodos Privados */

        private static WS_UserProxy.WS_User getWS()
        {
            try
            {
                WS_UserProxy.WS_User ws = new WS_UserProxy.WS_User();
                ws.PreAuthenticate = true;
                ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
                return ws;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion



        #region /* Métodos Públicos */

        public static List<UserInfo> SelectAll()
        {
            try
            {
                return Serializacao<List<UserInfo>>.FromXML(getWS().SelectAll());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static List<UserInfo> SelectByAnyFilters(UserInfo info)
        {
            try
            {
                String ListParameters;
                ListParameters = Serializacao<UserInfo>.ToXML(info);

                return Serializacao<List<UserInfo>>.FromXML(getWS().SelectByAnyFilters(ListParameters));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int Insert(UserInfo info)
        {
            try
            {
                String ListParameters;
                ListParameters = Serializacao<UserInfo>.ToXML(info);

                return getWS().Insert(ListParameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void Update(UserInfo info)
        {
            try
            {
                String ListParameters;
                ListParameters = Serializacao<UserInfo>.ToXML(info);

                getWS().Update(ListParameters);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static void Delete(int UserID)
        {
            try
            {
                getWS().Delete(UserID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
